home *** CD-ROM | disk | FTP | other *** search
- // GlueWindowINIT4.1.c
-
- // inclusion of files ------------------------------
-
- #include <SetUpA4.h> // To use globals in INIT.
- #include <OSUtils.h> // To check whether Gestalt is available or not.
- #include <Sound.h> // To use sound resources.
- #include "GlueWindow4.1.h" // Inclusion of definition.
-
- // definition --------------------------------------
-
- #define key1 (**setting_hdl).push_key
- #define key2 (**setting_hdl).pop_key
- #define key3 (**setting_hdl).drag_key
- #define gray_rect my_qd_globals.screenBits.bounds
- #define PUSH_RSRC 0
- #define POP_RSRC 1
- #define menu_bar_height 20
-
- // declaration of prototypes -----------------------
-
- int abs(int i);
-
- pascal Boolean (*TrackGoAwayProc) (WindowPtr wp, Point mp);
- pascal void (*DragWindowProc) (WindowPtr wp, Point mp, Rect *r);
- pascal long (*GrowWindowProc) (WindowPtr wp, Point mp, Rect *r);
-
- pascal void call_push_window(WindowPtr wp, Point mp, Rect *r);
- pascal void call_pop_window (WindowPtr wp, Point mp, Rect *r);
-
- pascal Boolean call_original_go_away(WindowPtr wp, Point mp);
- pascal Boolean call_custom_go_away (WindowPtr wp, Point mp);
- pascal Boolean my_track_go_away (WindowPtr wp, Point mp);
-
-
- pascal void call_no_marquee_drag(WindowPtr wp, Point mp, Rect *r);
- pascal void call_original_drag (WindowPtr wp, Point mp, Rect *r);
- pascal void call_custom_drag (WindowPtr wp, Point mp, Rect *r);
- pascal void my_drag_window (WindowPtr wp, Point mp, Rect *r);
-
- pascal long call_original_grow (WindowPtr wp, Point mp, Rect *r);
- pascal long call_custom_grow (WindowPtr wp, Point mp, Rect *r);
- pascal long my_grow_window (WindowPtr wp, Point mp, Rect *r);
-
- void draw_marquee(Rect *marquee, Rect *gap);
- void copy_pattern(Pattern src_pat, Pattern dst_pat);
-
-
- pascal Handle Get1Resource_in_system_heap(OSType rType, short id);
- pascal OSErr my_gestalt_selector(OSType selector, long *responce);
- void set_my_selector(ProcPtr func_address);
-
- short NumToolboxTraps( void );
- TrapType GetTrapType(short theTrap);
- Boolean TrapAvailable(short theTrap);
-
- init_data_hdl load_setting(void);
- void save_setting(init_data_hdl sysheap_data_hdl, prefs_file *pf);
- int open_prefs_file(prefs_file *pf);
- void show_loading_icon(short which_icon);
- void do_loading(void);
- Boolean is_system7(void);
-
- void main(void);
-
- // declaration of globals --------------------------
-
- qd_globals my_qd_globals;
- init_data_hdl setting_hdl = nil;
- Handle my_push_snd_hdl = nil;
- Handle my_pop_snd_hdl = nil;
-
- // main routines -----------------------------------
-
- void main(void)
- {
- RememberA0(); // RememberA0(), SetUpA4() and RestoreA4() are keywords
- SetUpA4(); // to use globals in code resources with THINK C.
-
- if(is_system7()) {
- InitGraf(&my_qd_globals.thePort); // This initialization is to show the startup icon.
- do_loading();
- }
- RestoreA4();
- }
-
- Boolean is_system7(void)
- {
- Boolean f;
- OSErr err;
- long r;
-
- if(f = TrapAvailable(_Gestalt)) {
- // You have to check like this before using Gestalt.
- err = Gestalt(gestaltSystemVersion, &r);
- if(err != noErr) f = false;
- else if(r <0x0700) f = false;
- else f = true;
- }
- return(f);
- }
-
- void do_loading(void)
- {
- short icon_number = SHOW_OK_ICON;
- Handle h;
- Rect r;
- long drag_address, grow_address, away_address;
- ProcPtr selector_func_address;
-
- h = Get1Resource_in_system_heap('INIT', RSRC_NUMBER_BASE);
- if(h) {
- setting_hdl = load_setting();
- if(setting_hdl) {
- DetachResource(h); // If you don't detach,
- HLock(h); // resources are purged at the end of INIT.
- HNoPurge(h);
-
- // You can use 'trapped' system routines with following procedures.
-
- away_address = NGetTrapAddress(_TrackGoAway, ToolTrap);
- drag_address = NGetTrapAddress(_DragWindow, ToolTrap);
- grow_address = NGetTrapAddress(_GrowWindow, ToolTrap);
-
- TrackGoAwayProc = (pascal Boolean (*)(WindowPtr, Point))away_address;
- DragWindowProc = (pascal void (*)(WindowPtr, Point, Rect*))drag_address;
- GrowWindowProc = (pascal long (*)(WindowPtr, Point, Rect*))grow_address;
-
- NSetTrapAddress((long) my_track_go_away, _TrackGoAway, ToolTrap);
- NSetTrapAddress((long) my_drag_window, _DragWindow, ToolTrap);
- NSetTrapAddress((long) my_grow_window, _GrowWindow, ToolTrap);
-
- if(TrapAvailable(_SndPlay)) { // To use sound routines, you must check.
- my_push_snd_hdl = Get1Resource_in_system_heap('snd ',
- RSRC_NUMBER_BASE + PUSH_RSRC);
- if(my_push_snd_hdl) {
- DetachResource(my_push_snd_hdl);
- HLock(my_push_snd_hdl);
- HNoPurge(my_push_snd_hdl);
- my_pop_snd_hdl = Get1Resource_in_system_heap('snd ',
- RSRC_NUMBER_BASE + POP_RSRC);
- if(my_pop_snd_hdl) {
- DetachResource(my_pop_snd_hdl);
- HLock(my_pop_snd_hdl);
- HNoPurge(my_pop_snd_hdl);
- }
- }
- }
- selector_func_address = (ProcPtr)my_gestalt_selector;
- set_my_selector(selector_func_address);
- if(!(**setting_hdl).show_init_icon) {
- icon_number = SHOW_NO_ICON;
- }
- }
- else {
- icon_number = SHOW_NG_ICON;
- ReleaseResource(h);
- // If loading is failed, the 'INIT' resource is released.
- }
- } else icon_number = SHOW_NG_ICON;
- show_loading_icon(icon_number);
- }
-
- void show_loading_icon(short which_icon)
- {
- Handle icon_h = nil;
- GrafPtr saved_port;
- GrafPort temp_port;
- Rect r;
- short screen_width;
- Boolean color_icon;
-
- if(which_icon != SHOW_NO_ICON) {
- color_icon = TrapAvailable(_GetCIcon);
- // Sometimes you can't use 'cicn' color icon resources
- // because GetCIcon and PlotCIcon are not implemented.
- if(color_icon)
- icon_h = (Handle)GetCIcon(RSRC_NUMBER_BASE + which_icon);
- else
- icon_h = GetIcon(RSRC_NUMBER_BASE + which_icon);
- if(icon_h) {
- HNoPurge(icon_h);
- GetPort(&saved_port);
- OpenPort(&temp_port);
- SetPort(&temp_port);
- if(((icon_loc_h << 1) ^ 0x1021) != icon_loc_cs) icon_loc_h = 8;
- screen_width = ((temp_port.portRect.right -
- temp_port.portRect.left) / 40) * 40;
- r.left = icon_loc_h % screen_width;
- r.right = r.left + 32;
- r.top = temp_port.portRect.bottom -
- (40 * (1 + icon_loc_h / screen_width));
- r.bottom = r.top + 32;
- if(color_icon)
- PlotCIcon(&r, (CIconHandle)icon_h);
- else
- PlotIcon(&r, icon_h);
- icon_loc_h += 40;
- icon_loc_cs = (icon_loc_h<<1) ^ 0x1021;
- if(color_icon)
- DisposeCIcon((CIconHandle)icon_h);
- else
- DisposeHandle(icon_h);
- SetPort(saved_port);
- ClosePort(&temp_port);
- }
- }
- }
-
- // gestalt check routines ----------------------------------
-
- #define TrapMask 0x0800
-
- short NumToolboxTraps( void )
- {
- if (NGetTrapAddress(_InitGraf, ToolTrap) ==
- NGetTrapAddress(0xAA6E, ToolTrap))
- return(0x0200);
- else
- return(0x0400);
- }
-
- TrapType GetTrapType(short theTrap)
- {
-
- if ((theTrap & TrapMask) > 0)
- return(ToolTrap);
- else
- return(OSTrap);
-
- }
-
- Boolean TrapAvailable(short theTrap)
- {
-
- TrapType tType;
-
- tType = GetTrapType(theTrap);
- if (tType == ToolTrap)
- theTrap = theTrap & 0x07FF;
- if (theTrap >= NumToolboxTraps())
- theTrap = _Unimplemented;
-
- return (NGetTrapAddress(theTrap, tType) !=
- NGetTrapAddress(_Unimplemented, ToolTrap));
- }
-
- // setting gestalt routines -------------------------
-
- void set_my_selector(ProcPtr func_address)
- {
- OSErr er;
-
- if(TrapAvailable(_Gestalt)) {
- SetUpA4();
- er = NewGestalt(CREATOR, func_address);
- // To hand address of INIT globals to cdev, you can use NewGestalt.
- RestoreA4();
- }
- }
-
- pascal OSErr my_gestalt_selector(OSType selector, long *responce)
- {
- SetUpA4();
- *responce = (long)setting_hdl;
- RestoreA4(); // All you have to do is wriiten here.
- return(NO_ERROR);
- }
-
- pascal Handle Get1Resource_in_system_heap(OSType rType, short id)
- {
- THz oldZone;
- Handle h;
-
- oldZone = GetZone();
- SetZone(SystemZone());
- h = Get1Resource(rType, id);
- SetZone(oldZone);
- return(h);
- }
-
- // data routines -----------------------------------
-
- init_data_hdl load_setting(void)
- {
- init_data_hdl h = nil, work_h = nil;
- old_init_data_hdl old_h;
- prefs_file pf;
- int er;
- short saved_ref_num;
-
- saved_ref_num = CurResFile();
- er = open_prefs_file(&pf);
- // pf is struct which contains all parameters to use preferences file.
- if(er == NO_ERROR) {
- h = (init_data_hdl)Get1Resource_in_system_heap(SETTING_RSRC, RSRC_NUMBER_BASE + 1);
- if(h) {
- HNoPurge((Handle)h);
- DetachResource((Handle)h);
- }
- else {
- old_h = (old_init_data_hdl)Get1Resource(SETTING_RSRC, RSRC_NUMBER_BASE);
- if(old_h) {
- h = (init_data_hdl)NewHandleSys(sizeof(init_data));
- if(h) {
- (**h).drag_on = (**old_h).drag_on;
- (**h).grow_on = (**old_h).grow_on;
- (**h).push_on = (**old_h).push_on;
- (**h).pop_on = (**old_h).pop_on;
- (**h).push_sound = (**old_h).push_sound;
- (**h).pop_sound = (**old_h).pop_sound;
- (**h).push_key[0] = (**old_h).push_key[0];
- (**h).push_key[1] = (**old_h).push_key[1];
- (**h).push_key[2] = (**old_h).push_key[2];
- (**h).push_key[3] = (**old_h).push_key[3];
- (**h).pop_key[0] = (**old_h).pop_key[0];
- (**h).pop_key[1] = (**old_h).pop_key[1];
- (**h).pop_key[2] = (**old_h).pop_key[2];
- (**h).pop_key[3] = (**old_h).pop_key[3];
- (**h).show_init_icon= (**old_h).show_init_icon;
- (**h).no_marquee = false;
- (**h).drag_key[0] = false;
- (**h).drag_key[1] = false;
- (**h).drag_key[2] = false;
- (**h).drag_key[3] = true;
- ReleaseResource((Handle)old_h);
- save_setting(h, &pf);
- }
- }
- }
- CloseResFile(pf.RsrcRefNum);
- }
- else if(er == OPEN_ERROR) {
- h = (init_data_hdl)NewHandleSys(sizeof(init_data));
- if(h) {
- (**h).drag_on = true;
- (**h).grow_on = true;
- (**h).push_on = true;
- (**h).pop_on = true;
- (**h).push_sound = true;
- (**h).pop_sound = true;
- (**h).push_key[0] = false;
- (**h).push_key[1] = true;
- (**h).push_key[2] = false;
- (**h).push_key[3] = false;
- (**h).pop_key[0] = true;
- (**h).pop_key[1] = false;
- (**h).pop_key[2] = false;
- (**h).pop_key[3] = false;
- (**h).show_init_icon= true;
- (**h).no_marquee = false;
- (**h).drag_key[0] = false;
- (**h).drag_key[1] = false;
- (**h).drag_key[2] = false;
- (**h).drag_key[3] = true;
- save_setting(h, &pf);
- }
- }
- UseResFile(saved_ref_num);
- return(h);
- }
-
- void save_setting(init_data_hdl sysheap_data_hdl, prefs_file *pf_ptr)
- {
- Handle h;
- init_data_hdl work_h;
- OSErr err;
- FInfo f_info;
-
- HCreateResFile(pf_ptr->vRefNum, pf_ptr->DirID, PREFS_TITLE);
- f_info.fdType = 'pref';
- f_info.fdCreator = CREATOR;
- f_info.fdFlags = 0;
- HSetFInfo(pf_ptr->vRefNum, pf_ptr->DirID, PREFS_TITLE, &f_info);
- open_prefs_file(pf_ptr); // HSetFInfo close a resource file, so you must open again.
-
- work_h = (init_data_hdl)NewHandle(sizeof(init_data));
- if(work_h) {
- **work_h = **sysheap_data_hdl;
- if(h = Get1Resource(SETTING_RSRC, RSRC_NUMBER_BASE + 1))
- RmveResource(h);
- AddResource((Handle)work_h, SETTING_RSRC, RSRC_NUMBER_BASE + 1, "\p");
- ReleaseResource((Handle)work_h);
- CloseResFile(pf_ptr->RsrcRefNum);
- }
- }
-
- int open_prefs_file(prefs_file *pf_ptr)
- {
- OSErr er;
- int rn;
-
- er = FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder,
- &(pf_ptr->vRefNum), &(pf_ptr->DirID));
- if(er == 0) {
- rn = HOpenResFile(pf_ptr->vRefNum, pf_ptr->DirID, PREFS_TITLE, fsRdWrPerm);
- if(rn != -1) {
- pf_ptr->RsrcRefNum = rn;
- return(NO_ERROR);
- }
- return(OPEN_ERROR);
- }
- return(CAUTION_ERROR);
- }
-
- // trap routines -----------------------------------
-
- pascal Boolean my_track_go_away(WindowPtr wp, Point mp)
- {
- KeyMap my_keymap;
- Boolean f;
-
- SetUpA4();
- GetKeys(my_keymap);
- if( (**setting_hdl).pop_on &&
- (key2[0] == BitTst(my_keymap, CONTROL_KEY)) &&
- (key2[1] == BitTst(my_keymap, SHIFT_KEY)) &&
- (key2[2] == BitTst(my_keymap, OPTION_KEY)) &&
- (key2[3] == BitTst(my_keymap, COMMAND_KEY)) )
- f = call_custom_go_away(wp, mp);
- else f = call_original_go_away(wp, mp);
- RestoreA4();
- return(f);
- }
-
- pascal Boolean call_original_go_away(WindowPtr wp, Point mp)
- {
- Boolean f;
-
- f = (*TrackGoAwayProc)(wp, mp);
- return(f);
- }
-
- pascal Boolean call_custom_go_away(WindowPtr wp, Point mp)
- {
- Boolean f;
- Point pt;
- GrafPtr saved_port;
-
- f = call_original_go_away(wp, mp);
- if(f) {
- GetPort(&saved_port);
- SetPort(wp);
- MoveWindow(wp, std_state.left, std_state.top, false);
- SetPort(saved_port);
- }
- if((**setting_hdl).pop_sound) {
- if(TrapAvailable(_SndPlay) && my_pop_snd_hdl)
- SndPlay(nil, my_pop_snd_hdl, false);
- else SysBeep(1);
- }
- return(f);
- }
-
- pascal void my_drag_window(WindowPtr wp, Point mp, Rect *r)
- {
- KeyMap my_keymap;
- Rect dummy_rect;
-
- SetUpA4();
- GetKeys(my_keymap);
- if(!setting_hdl) call_original_drag(wp, mp, r);
- else if((**setting_hdl).no_marquee &&
- (key3[0] == BitTst(my_keymap, CONTROL_KEY)) &&
- (key3[1] == BitTst(my_keymap, SHIFT_KEY)) &&
- (key3[2] == BitTst(my_keymap, OPTION_KEY)) &&
- (key3[3] == BitTst(my_keymap, COMMAND_KEY)) )
- call_no_marquee_drag(wp, mp, r);
- else if((**setting_hdl).push_on &&
- (key1[0] == BitTst(my_keymap, CONTROL_KEY)) &&
- (key1[1] == BitTst(my_keymap, SHIFT_KEY)) &&
- (key1[2] == BitTst(my_keymap, OPTION_KEY)) &&
- (key1[3] == BitTst(my_keymap, COMMAND_KEY)) )
- call_push_window(wp, mp, r);
- else if((**setting_hdl).pop_on &&
- (key2[0] == BitTst(my_keymap, CONTROL_KEY)) &&
- (key2[1] == BitTst(my_keymap, SHIFT_KEY)) &&
- (key2[2] == BitTst(my_keymap, OPTION_KEY)) &&
- (key2[3] == BitTst(my_keymap, COMMAND_KEY)) )
- call_pop_window(wp, mp, r);
- else if(!(**setting_hdl).drag_on) call_original_drag(wp, mp, r);
- else call_custom_drag(wp, mp, r);
- RestoreA4();
- }
-
- pascal void call_original_drag(WindowPtr wp, Point mp, Rect *r)
- {
- (*DragWindowProc)(wp, mp, r);
- }
-
- pascal long my_grow_window(WindowPtr wp, Point mp, Rect *r)
- {
- KeyMap my_keymap;
- long v;
-
- SetUpA4();
- GetKeys(my_keymap);
-
- if(!setting_hdl)
- v = call_original_grow(wp, mp, r);
- else if(!(**setting_hdl).grow_on)
- v = call_original_grow(wp, mp, r);
- else v = call_custom_grow(wp, mp, r);
- RestoreA4();
- return(v);
- }
-
- pascal long call_original_grow(WindowPtr wp, Point mp, Rect *r)
- {
- long v;
-
- v = (*GrowWindowProc)(wp, mp, r);
-
- return(v);
- }
-
- pascal void call_push_window(WindowPtr wp, Point mp, Rect *r)
- {
- GrafPtr saved_port;
-
- GetPort(&saved_port);
- SetPort(wp);
- std_state.left = (**((WindowPeek)wp)->contRgn).rgnBBox.left;
- std_state.top = (**((WindowPeek)wp)->contRgn).rgnBBox.top;
- SetPort(saved_port);
- if((**setting_hdl).push_sound) {
- if(TrapAvailable(_SndPlay) && my_push_snd_hdl)
- SndPlay(nil, my_push_snd_hdl, false);
- else SysBeep(1);
- }
- return;
- }
-
- pascal void call_pop_window(WindowPtr wp, Point mp, Rect *r)
- {
- GrafPtr saved_port;
-
- GetPort(&saved_port);
- SetPort(wp);
- MoveWindow(wp, std_state.left, std_state.top, false);
- SetPort(saved_port);
- if((**setting_hdl).pop_sound) {
- if(TrapAvailable(_SndPlay) && my_pop_snd_hdl)
- SndPlay(nil, my_pop_snd_hdl, false);
- else SysBeep(1);
- }
- return;
- }
-
-
- pascal void call_custom_drag(WindowPtr wp, Point mp, Rect *r)
- {
- GrafPtr saved_port;
- Point old_pt_g, new_pt_g, p, spread_l_to_g, saved_pt_g, mp_g,
- offset, w_g, saved_pn_size;
- WindowPeek wpk;
- Boolean h_changed, v_changed, color_qd;
- Rect wpk_rect_g, saved_rect_g, marquee_spread_l, c_rect_g, s_rect_g,
- gap, r_g, work_r;
- short c_width, c_height, screen_width, screen_height;
- PenState saved_pen_state;
- char i;
- RgnHandle new_rgn, saved_vis_rgn, saved_clip_rgn, s_rgn_g, marquee_rgn_spread_l;
- RGBColor fore_color, back_color;
- PixPatHandle saved_pn_pp_hdl, saved_fill_pp_hdl, saved_bk_pp_hdl,
- dummy_pn_pp_hdl, dummy_fill_pp_hdl, dummy_bk_pp_hdl;
- Pattern saved_bk_pat, saved_fill_pat, saved_pn_pat;
- short saved_pn_mode;
-
-
- GetPort(&saved_port);
-
- if(color_qd = TrapAvailable(_GetForeColor)) {
- GetForeColor(&fore_color);
- GetBackColor(&back_color);
- dummy_bk_pp_hdl = NewPixPat();
- dummy_pn_pp_hdl = NewPixPat();
- dummy_fill_pp_hdl = NewPixPat();
- saved_bk_pp_hdl = ((CGrafPtr)wp)->bkPixPat;
- saved_pn_pp_hdl = ((CGrafPtr)wp)->pnPixPat;
- saved_fill_pp_hdl = ((CGrafPtr)wp)->fillPixPat;
- ((CGrafPtr)wp)->bkPixPat = dummy_bk_pp_hdl;
- ((CGrafPtr)wp)->pnPixPat = dummy_pn_pp_hdl;
- ((CGrafPtr)wp)->fillPixPat = dummy_fill_pp_hdl;
- // PenPat changes members of pnPixPat structure if current GrafPort
- // is color GrafPort.
- // If current GrafPort is color only, use CopyPixPat.
- }
- else {
- copy_pattern(wp->pnPat, saved_pn_pat);
- copy_pattern(wp->bkPat, saved_bk_pat);
- copy_pattern(wp->fillPat, saved_fill_pat);
- }
- saved_pn_mode = wp->pnMode;
- saved_pn_size = wp->pnSize;
- // I used to use GetPenState. But I feel that GetPenState offen
- // work properly. So I copy pnSize and pnMode direct.
-
- SetPort(wp);
- mp_g = mp;
-
- new_rgn = NewRgn();
- saved_vis_rgn = NewRgn();
- saved_clip_rgn = NewRgn();
- // vis & clipRgn seem not to be changed if you change without using system
- // routines like SetClip. Especially visRgn (it has no system routine).
-
- marquee_rgn_spread_l = NewRgn();
-
- CopyRgn(wp->visRgn, saved_vis_rgn); // Don't forget NewRgn before CopyRgn!
- CopyRgn(wp->clipRgn, saved_clip_rgn);
-
- saved_pt_g.h = wp->portRect.right;
- saved_pt_g.v = wp->portRect.bottom;
- LocalToGlobal(&saved_pt_g);
- saved_rect_g.right = saved_pt_g.h;
- saved_rect_g.bottom = saved_pt_g.v;
- saved_pt_g.h = wp->portRect.left;
- saved_pt_g.v = wp->portRect.top;
- LocalToGlobal(&saved_pt_g);
- saved_rect_g.left = saved_pt_g.h;
- saved_rect_g.top = saved_pt_g.v;
- // 'g' in 'saved_rect_g' etc. mean global coordinates.
- // 'saved_pt_g' shows the top-left corner of portRect.
-
- offset.h = mp_g.h - saved_pt_g.h;
- offset.v = mp_g.v - saved_pt_g.v;
- // 'offset's are differences between the coordinates of
- // mouse point and top-left of portRect. Normally plus.
-
- c_rect_g = (**((WindowPeek)wp)->contRgn).rgnBBox;
- s_rgn_g = ((WindowPeek)wp)->strucRgn;
- s_rect_g = (**s_rgn_g).rgnBBox;
-
- gap.left = saved_rect_g.left - s_rect_g.left;
- gap.top = saved_rect_g.top - s_rect_g.top;
- gap.right = s_rect_g.right - saved_rect_g.right;
- gap.bottom = s_rect_g.bottom - saved_rect_g.bottom;
- // These 'gap's are differences between portRect and
- // structure rectangle. These are also plus.
-
- c_width = saved_rect_g.right - saved_rect_g.left;
- c_height = saved_rect_g.bottom - saved_rect_g.top;
- screen_width = gray_rect.right - gray_rect.left;
- screen_height = gray_rect.bottom - gray_rect.top - menu_bar_height;
-
- PortSize(screen_width, screen_height);
- // Spread current grafport to draw the marquee.
-
- MovePortTo(gray_rect.left, gray_rect.top + menu_bar_height);
- // PortChanged((GrafPtr)wp);
- RectRgn(new_rgn, &(wp->portRect));
- UnionRgn(new_rgn, wp->visRgn, wp->visRgn);
- UnionRgn(new_rgn, wp->clipRgn, wp->clipRgn);
- DisposeRgn(new_rgn);
- // PortChanged((GrafPtr)wp);
- SetPort(wp);
- // vis & clipRgn are setted here.
- // PortChanged is sometimes unimplemented (especially old Mac).
- // So you had better to use SetPort if you want to change property of grafport
- // without use of system routines.
-
- p.h = s_rect_g.left;
- p.v = s_rect_g.top;
- GlobalToLocal(&p);
- spread_l_to_g.h = s_rect_g.left - p.h;
- spread_l_to_g.v = s_rect_g.top - p.v;
- // These 'spread_l_to_g's are differences between
- // 'spreaded' local coordinates and global.
- // Adding spread_l_to_g converts suspended local coordinates to global.
- // And substracting spread_l_to_g converts global to suspended local.
-
- r_g = *r;
- work_r = gray_rect;
- work_r.top += menu_bar_height + 2;
- SectRect(&r_g, &work_r, &r_g);
-
- CopyRgn(s_rgn_g, marquee_rgn_spread_l);
- OffsetRgn(marquee_rgn_spread_l, - spread_l_to_g.h, - spread_l_to_g.v);
- // Rgn is prepared as Handle. So "marquee_rgn = s_rgn" is wrong if you don't
- // want to touch original strucRgn.
- // And move the marquee to the proper spreaded local point.
-
- PenSize(1,1);
- PenMode(patXor);
- PenPat(my_qd_globals.gray);
-
- FrameRgn(marquee_rgn_spread_l);
-
- old_pt_g = mp_g;
-
- w_g.h = saved_rect_g.left;
- w_g.v = saved_rect_g.top;
-
- while(StillDown()) {
- GetMouse(&new_pt_g);
- LocalToGlobal(&new_pt_g);
- if(PtInRect(new_pt_g, &r_g)) {
- if (!EqualPt(new_pt_g, old_pt_g)) {
- w_g.h = new_pt_g.h - offset.h;
- w_g.v = new_pt_g.v - offset.v;
- h_changed = v_changed = false;
- wpk = (WindowPeek)FrontWindow();
- while(wpk) {
- if(wpk != (WindowPeek)wp) {
- wpk_rect_g = (**wpk->strucRgn).rgnBBox;
- if(!h_changed &&(abs(wpk_rect_g.left
- - (w_g.h - gap.left)) <= 5)) {
- w_g.h = wpk_rect_g.left + gap.left;
- h_changed = true;
- }
- if(!h_changed &&(abs(wpk_rect_g.right
- - (w_g.h - gap.left)) <= 5)) {
- w_g.h = wpk_rect_g.right + gap.left;
- h_changed = true;
- }
- if(!h_changed &&(abs(wpk_rect_g.left
- - (w_g.h + c_width + gap.right)) <= 5)) {
- w_g.h = wpk_rect_g.left - c_width - gap.right;
- h_changed = true;
- }
- if(!h_changed &&(abs(wpk_rect_g.right
- - (w_g.h + c_width + gap.right)) <= 5)) {
- w_g.h = wpk_rect_g.right - c_width - gap.right;
- h_changed = true;
- }
- if(!v_changed &&(abs(wpk_rect_g.top
- - (w_g.v - gap.top)) <= 5)) {
- w_g.v = wpk_rect_g.top + gap.top;
- v_changed = true;
- }
- if(!v_changed &&(abs(wpk_rect_g.bottom
- - (w_g.v - gap.top)) <= 5)) {
- w_g.v = wpk_rect_g.bottom + gap.top;
- v_changed = true;
- }
- if(!v_changed &&(abs(wpk_rect_g.top
- - (w_g.v + c_height + gap.bottom)) <= 5)) {
- w_g.v = wpk_rect_g.top - c_height - gap.bottom;
- v_changed = true;
- }
- if(!v_changed &&(abs(wpk_rect_g.bottom
- - (w_g.v + c_height + gap.bottom)) <= 5)) {
- w_g.v = wpk_rect_g.bottom - c_height- gap.bottom;
- v_changed = true;
- }
- wpk = wpk->nextWindow;
- if(h_changed && v_changed) wpk = (WindowPeek)0;
- }
- else {
- wpk = wpk->nextWindow;
- }
-
- }
- FrameRgn(marquee_rgn_spread_l);
-
- OffsetRgn(marquee_rgn_spread_l,
- w_g.h - gap.left - spread_l_to_g.h
- - (**marquee_rgn_spread_l).rgnBBox.left,
- w_g.v - gap.top - spread_l_to_g.v
- - (**marquee_rgn_spread_l).rgnBBox.top);
- // 'w_g's show top-left corner of portRect.
- // And portRect has local coordinates.
-
- FrameRgn(marquee_rgn_spread_l);
- old_pt_g = new_pt_g;
- }
- }
- }
- FrameRgn(marquee_rgn_spread_l);
- PortSize(saved_rect_g.right - saved_rect_g.left,
- saved_rect_g.bottom - saved_rect_g.top);
- MovePortTo(saved_pt_g.h, saved_pt_g.v);
- CopyRgn(saved_vis_rgn, wp->visRgn);
- CopyRgn(saved_clip_rgn, wp->clipRgn);
- // PortChanged((GrafPtr)wp);
- MoveWindow(wp, w_g.h, w_g.v, false);
- DisposeRgn(marquee_rgn_spread_l);
- DisposeRgn(saved_vis_rgn);
- DisposeRgn(saved_clip_rgn); // Don't forget DisposeRgn!
- SetPort(wp);
- SetPort(saved_port);
-
- if(color_qd) {
- RGBForeColor(&fore_color);
- RGBBackColor(&back_color);
- ((CGrafPtr)wp)->bkPixPat = saved_bk_pp_hdl;
- ((CGrafPtr)wp)->pnPixPat = saved_pn_pp_hdl;
- ((CGrafPtr)wp)->fillPixPat = saved_fill_pp_hdl;
- DisposePixPat(dummy_bk_pp_hdl);
- DisposePixPat(dummy_pn_pp_hdl);
- DisposePixPat(dummy_fill_pp_hdl);
- }
- else {
- copy_pattern(saved_bk_pat, wp->bkPat);
- copy_pattern(saved_fill_pat, wp->fillPat);
- copy_pattern(saved_pn_pat, wp->pnPat);
- }
- wp->pnSize = saved_pn_size;
- wp->pnMode = saved_pn_mode;
- }
-
- void copy_pattern(Pattern src_pat, Pattern dst_pat)
- {
- int i;
-
- for(i = 0; i <= 7; i++) {
- dst_pat[i] = src_pat[i];
- }
- }
-
- pascal void call_no_marquee_drag(WindowPtr wp, Point mp, Rect *r)
- {
- GrafPtr saved_port;
- Point old_pt, new_pt;
- short offset_h, offset_v;
- WindowPeek wpk;
- Boolean h_changed, v_changed;
- Rect wpk_rect;
- short w_width, w_height;
- short w_left, w_top;
- short gap_left, gap_top, gap_right, gap_bottom;
-
- GetPort(&saved_port);
- SetPort(wp);
- offset_h = mp.h - (**((WindowPeek)wp)->contRgn).rgnBBox.left;
- offset_v = mp.v - (**((WindowPeek)wp)->contRgn).rgnBBox.top;
- gap_left = (**((WindowPeek)wp)->contRgn).rgnBBox.left - (**((WindowPeek)wp)->strucRgn).rgnBBox.left;
- gap_top = (**((WindowPeek)wp)->contRgn).rgnBBox.top - (**((WindowPeek)wp)->strucRgn).rgnBBox.top;
- gap_right = (**((WindowPeek)wp)->strucRgn).rgnBBox.right - (**((WindowPeek)wp)->contRgn).rgnBBox.right;
- gap_bottom = (**((WindowPeek)wp)->strucRgn).rgnBBox.bottom - (**((WindowPeek)wp)->contRgn).rgnBBox.bottom;
- w_width = (**((WindowPeek)wp)->contRgn).rgnBBox.right
- - (**((WindowPeek)wp)->contRgn).rgnBBox.left;
- w_height = (**((WindowPeek)wp)->contRgn).rgnBBox.bottom
- - (**((WindowPeek)wp)->contRgn).rgnBBox.top;
- old_pt = mp;
- while (StillDown()) {
- GetMouse(&new_pt);
- LocalToGlobal(&new_pt);
- if (PtInRect(new_pt, r)) {
- if (!EqualPt(new_pt, old_pt)) {
- w_left = new_pt.h - offset_h;
- w_top = new_pt.v - offset_v;
- h_changed = v_changed = false;
-
- wpk = (WindowPeek)FrontWindow();
- while(wpk) {
- if(wpk != (WindowPeek)wp) {
- wpk_rect = (**wpk->strucRgn).rgnBBox;
- if (!h_changed &&(abs(wpk_rect.left - (w_left - gap_left)) <= 5)) {
- w_left = wpk_rect.left + gap_left;
- h_changed = true;
- }
- if (!h_changed &&(abs(wpk_rect.right - (w_left - gap_left)) <= 5)) {
- w_left = wpk_rect.right + gap_left;
- h_changed = true;
- }
- if (!h_changed &&(abs(wpk_rect.left - (w_left + w_width + gap_right)) <= 5)) {
- w_left = wpk_rect.left - w_width - gap_right;
- h_changed = true;
- }
- if (!h_changed &&(abs(wpk_rect.right - (w_left + w_width + gap_right)) <= 5)) {
- w_left = wpk_rect.right - w_width - gap_right;
- h_changed = true;
- }
- if (!v_changed &&(abs(wpk_rect.top - (w_top - gap_top)) <= 5)) {
- w_top = wpk_rect.top + gap_top;
- v_changed = true;
- }
- if (!v_changed &&(abs(wpk_rect.bottom - (w_top - gap_top)) <= 5)) {
- w_top = wpk_rect.bottom + gap_top;
- v_changed = true;
- }
- if (!v_changed &&(abs(wpk_rect.top - (w_top + w_height + gap_bottom)) <= 5)) {
- w_top = wpk_rect.top - w_height - gap_bottom;
- v_changed = true;
- }
- if (!v_changed &&(abs(wpk_rect.bottom - (w_top + w_height + gap_bottom)) <= 5)) {
- w_top = wpk_rect.bottom - w_height - gap_bottom;
- v_changed = true;
- }
- wpk = wpk->nextWindow;
- if(h_changed && v_changed) wpk = (WindowPeek)0;
- } else {
- wpk = wpk->nextWindow;
- }
- }
-
- MoveWindow(wp, w_left, w_top, false);
- old_pt = new_pt;
- }
- }
- }
- SetPort(saved_port);
- }
-
-
- pascal long call_custom_grow(WindowPtr wp, Point mp, Rect *r)
- {
- GrafPtr saved_port;
- Point old_pt_g, new_pt_g, p, spread_l_to_g, saved_pt_g, mp_g, offset,
- w_g, old_l_to_g, saved_pn_size;
- WindowPeek wpk;
- Boolean h_changed, v_changed, color_qd;
- KeyMap my_keymap;
- Rect wpk_rect_g, saved_rect_g, marquee_spread_l, c_rect_g, s_rect_g,
- gap, r_g;
- short c_width, c_height, screen_width, screen_height;
- long return_value = 0;
- PenState saved_pen_state;
- RGBColor fore_color, back_color;
- long l;
- RgnHandle new_rgn, saved_vis_rgn, saved_clip_rgn;
- PixPatHandle saved_pn_pp_hdl, saved_fill_pp_hdl, saved_bk_pp_hdl,
- dummy_pn_pp_hdl, dummy_fill_pp_hdl, dummy_bk_pp_hdl;
- Pattern saved_bk_pat, saved_fill_pat, saved_pn_pat;
- short saved_pn_mode;
-
- GetPort(&saved_port);
- if(color_qd = TrapAvailable(_GetForeColor)) {
- GetForeColor(&fore_color);
- GetBackColor(&back_color);
- dummy_bk_pp_hdl = NewPixPat();
- dummy_pn_pp_hdl = NewPixPat();
- dummy_fill_pp_hdl = NewPixPat();
- saved_bk_pp_hdl = ((CGrafPtr)wp)->bkPixPat;
- saved_pn_pp_hdl = ((CGrafPtr)wp)->pnPixPat;
- saved_fill_pp_hdl = ((CGrafPtr)wp)->fillPixPat;
- ((CGrafPtr)wp)->bkPixPat = dummy_bk_pp_hdl;
- ((CGrafPtr)wp)->pnPixPat = dummy_pn_pp_hdl;
- ((CGrafPtr)wp)->fillPixPat = dummy_fill_pp_hdl;
- }
- else {
- copy_pattern(wp->pnPat, saved_pn_pat);
- copy_pattern(wp->bkPat, saved_bk_pat);
- copy_pattern(wp->fillPat, saved_fill_pat);
- }
- saved_pn_mode = wp->pnMode;
- saved_pn_size = wp->pnSize;
-
- SetPort(wp);
- mp_g = mp;
-
- old_l_to_g.h = wp->portRect.left;
- old_l_to_g.v = wp->portRect.top;
- LocalToGlobal(&old_l_to_g);
- // Adding old_l_to_g converts old (not spreaded) local coordinates to global.
-
- r_g = *r;
- // r shows the restrict "size" here.
-
- if(r_g.right > gray_rect.right)
- r_g.right = gray_rect.right;
- // Set maximum window size(horizontal) to appropriate size.
-
- if(r_g.bottom > gray_rect.bottom)
- r_g.bottom = gray_rect.bottom;
- // Set maximum window size(vertical) to appropriate size.
-
- OffsetRect(&r_g, old_l_to_g.h, old_l_to_g.v);
- // Here, r shows the restrict rectangle (coordinations).
-
- new_rgn = NewRgn();
- saved_vis_rgn = NewRgn();
- saved_clip_rgn = NewRgn();
-
- CopyRgn(wp->visRgn, saved_vis_rgn);
- CopyRgn(wp->clipRgn, saved_clip_rgn);
-
- saved_pt_g.h = wp->portRect.right;
- saved_pt_g.v = wp->portRect.bottom;
- LocalToGlobal(&saved_pt_g);
- saved_rect_g.right = saved_pt_g.h;
- saved_rect_g.bottom = saved_pt_g.v;
- saved_pt_g.h = wp->portRect.left;
- saved_pt_g.v = wp->portRect.top;
- LocalToGlobal(&saved_pt_g);
- saved_rect_g.left = saved_pt_g.h;
- saved_rect_g.top = saved_pt_g.v;
-
- offset.h = saved_rect_g.right - mp.h;
- offset.v = saved_rect_g.bottom - mp.v;
-
- c_rect_g = (**((WindowPeek)wp)->contRgn).rgnBBox;
- s_rect_g = (**((WindowPeek)wp)->strucRgn).rgnBBox;
-
- gap.left = saved_rect_g.left - s_rect_g.left;
- gap.top = saved_rect_g.top - s_rect_g.top;
- gap.right = s_rect_g.right - saved_rect_g.right;
- gap.bottom = s_rect_g.bottom - saved_rect_g.bottom;
-
- c_width = saved_rect_g.right - saved_rect_g.left;
- c_height = saved_rect_g.bottom - saved_rect_g.top;
- screen_width = gray_rect.right - s_rect_g.left;
- screen_height = gray_rect.bottom - s_rect_g.top;
-
- PortSize(screen_width, screen_height);
- MovePortTo(s_rect_g.left, s_rect_g.top);
- // PortChanged((GrafPtr)wp);
- RectRgn(new_rgn, &(wp->portRect));
- UnionRgn(new_rgn, wp->visRgn, wp->visRgn);
- UnionRgn(new_rgn, wp->clipRgn, wp->clipRgn);
- DisposeRgn(new_rgn);
- // PortChanged((GrafPtr)wp);
- SetPort(wp);
-
- p.h = s_rect_g.left;
- p.v = s_rect_g.top;
- GlobalToLocal(&p);
- spread_l_to_g.h = s_rect_g.left - p.h;
- spread_l_to_g.v = s_rect_g.top - p.v;
-
- marquee_spread_l.left = s_rect_g.left - spread_l_to_g.h;
- marquee_spread_l.top = s_rect_g.top - spread_l_to_g.v;
- marquee_spread_l.right = s_rect_g.right - spread_l_to_g.h + 1;
- marquee_spread_l.bottom = s_rect_g.bottom - spread_l_to_g.v + 1;
- // '+ 1' is added because sysytem routine does so.
-
- PenSize(1,1);
- PenMode(patXor);
- PenPat(my_qd_globals.gray);
-
- draw_marquee(&marquee_spread_l, &gap);
-
- old_pt_g = mp_g;
- w_g.h = saved_rect_g.right;
- w_g.v = saved_rect_g.bottom;
-
- while(StillDown()) {
- GetMouse(&new_pt_g);
- new_pt_g.h += offset.h;
- new_pt_g.v += offset.v;
- LocalToGlobal(&new_pt_g);
- if(!PtInRect(new_pt_g, &r_g)) {
- // This checks too small or too larger window size.
-
- l = PinRect(&r_g, new_pt_g);
- if(new_pt_g.v != HiWord(l))
- new_pt_g.v = HiWord(l);
- if(new_pt_g.h != LoWord(l))
- new_pt_g.h = LoWord(l);
- }
- if(!EqualPt(new_pt_g, old_pt_g)) {
- w_g.h = new_pt_g.h;
- w_g.v = new_pt_g.v;
- h_changed = v_changed = false;
- GetKeys(my_keymap);
- if(BitTst(&my_keymap, OPTION_KEY)) {
- // If option key is pressed, the window grows every 5 pixels.
-
- w_g.h = (w_g.h / 5) * 5;
- w_g.v = (w_g.v / 5) * 5;
- }
- else {
- wpk = (WindowPeek)FrontWindow();
- while(wpk) {
- if(wpk != (WindowPeek)wp) {
- wpk_rect_g = (**wpk->strucRgn).rgnBBox;
- if (!h_changed && (abs(wpk_rect_g.left
- - (w_g.h + gap.right)) <= 5)) {
- w_g.h = wpk_rect_g.left - gap.right;
- h_changed = true;
- }
- if(!h_changed && (abs(wpk_rect_g.right
- - (w_g.h + gap.right)) <= 5)) {
- w_g.h = wpk_rect_g.right - gap.right;
- h_changed = true;
- }
-
- if(!v_changed && (abs(wpk_rect_g.top
- - (w_g.v + gap.bottom)) <= 5)) {
- w_g.v = wpk_rect_g.top - gap.bottom;
- v_changed = true;
- }
- if(!v_changed && (abs(wpk_rect_g.bottom
- - (w_g.v + gap.bottom)) <= 5)) {
- w_g.v = wpk_rect_g.bottom - gap.bottom;
- v_changed = true;
- }
-
- wpk = wpk->nextWindow;
- if(h_changed && v_changed)
- wpk = (WindowPeek)0;
- }
- else {
- wpk = wpk->nextWindow;
- }
- }
- }
- draw_marquee(&marquee_spread_l, &gap);
-
- marquee_spread_l.right = w_g.h + gap.right - spread_l_to_g.h - 1;
- marquee_spread_l.bottom = w_g.v + gap.bottom - spread_l_to_g.v - 1;
- // '- 1' is added because '+ 1' was added :-)
-
- draw_marquee(&marquee_spread_l, &gap);
-
- c_width = w_g.h - saved_rect_g.left;
- c_height = w_g.v - saved_rect_g.top;
- old_pt_g = new_pt_g;
- }
- }
-
- draw_marquee(&marquee_spread_l, &gap);
-
- PortSize(saved_rect_g.right - saved_rect_g.left,
- saved_rect_g.bottom - saved_rect_g.top);
- MovePortTo(saved_pt_g.h, saved_pt_g.v);
- CopyRgn(saved_vis_rgn, wp->visRgn);
- CopyRgn(saved_clip_rgn, wp->clipRgn);
- // PortChanged((GrafPtr)wp);
- DisposeRgn(saved_vis_rgn);
- DisposeRgn(saved_clip_rgn);
- SetPort(wp);
- SetPort(saved_port);
- SetPenState(&saved_pen_state);
- if(color_qd) {
- RGBForeColor(&fore_color);
- RGBBackColor(&back_color);
- ((CGrafPtr)wp)->bkPixPat = saved_bk_pp_hdl;
- ((CGrafPtr)wp)->pnPixPat = saved_pn_pp_hdl;
- ((CGrafPtr)wp)->fillPixPat = saved_fill_pp_hdl;
- DisposePixPat(dummy_bk_pp_hdl);
- DisposePixPat(dummy_pn_pp_hdl);
- DisposePixPat(dummy_fill_pp_hdl);
- }
- else {
- copy_pattern(saved_pn_pat, wp->pnPat);
- copy_pattern(saved_bk_pat, wp->bkPat);
- copy_pattern(saved_fill_pat, wp->fillPat);
- }
- wp->pnSize = saved_pn_size;
- wp->pnMode = saved_pn_mode;
-
- if((mp.h != old_pt_g.h - offset.h) || (mp.v != old_pt_g.v - offset.v)) {
- return_value = c_height;
- return_value <<= 16;
- return_value += c_width;
- }
- return(return_value);
- }
-
- void draw_marquee(Rect *marquee, Rect *gap)
- // This routine draws the complicated marquee used in call_custom_grow.
- {
- FrameRect(marquee);
- MoveTo(marquee->left, marquee->top + gap->top - 1);
- LineTo(marquee->right, marquee->top + gap->top - 1);
- MoveTo(marquee->left, marquee->bottom - 16);
- LineTo(marquee->right, marquee->bottom - 16);
- MoveTo(marquee->right - 16, marquee->top + gap->top);
- LineTo(marquee->right - 16, marquee->bottom);
- // 16 means width of scroll bar.
- }
-
-
-